<template>
  <el-dialog title="修改设备" :visible="showEditDialog" @close="btnCancel">
    <el-form ref="editOrder" :model="formData" label-width="120px">
      <el-form-item label="机器编号：">
        {{ equipmentList.innerCode }}
      </el-form-item>
      <el-form-item label="供货时间：">
        {{ equipmentList.lastSupplyTime }}
      </el-form-item>
      <el-form-item label="设备类型：">
        {{ equipmentList.type.name }}
      </el-form-item>
      <el-form-item label="设备容量：">
        {{ equipmentList.type.vmCol }}
      </el-form-item>
      <el-form-item label="设备点位：">
        <el-select v-model="formData.nodeId" placeholder="请选择">
          <el-option v-for="(value,index) in orderList" :key="index" :label="value.name" :value="value.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="合作商：">
        {{ equipmentList.ownerName }}
      </el-form-item>
      <el-form-item label="所属区域：">
        {{ equipmentList.region.name }}
      </el-form-item>
      <el-form-item label="设备地址：">
        {{ equipmentList.node.name }}
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-row type="flex" justify="center">
        <el-col :span="8">
          <el-button @click="btnCancel">取消</el-button>
          <el-button type="warning" @click="btnOK">确认</el-button>
        </el-col>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { editEquipment } from '@/api/equipment'
export default {
  props: {
    showEditDialog: {
      type: Boolean,
      default: false
    },
    equipmentList: {
      type: [Array, Object],
      required: true
    },
    orderList: {
      type: Array,
      required: true
    },
    equipmentId: {
      type: String,
      default: null
    },
    equipmentNodeId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      formData: {
        id: this.equipmentId,
        nodeId: this.equipmentNodeId
      }
    }
  },
  computed: {

  },
  methods: {
    async btnOK() {
      try {
        await editEquipment(this.equipmentId, this.formData.nodeId)
        this.$emit('update:showEditDialog', false)
        this.$emit('editEquipment')
        this.$message.success('修改成功')
      } catch (error) {
        console.log(error)
      }
    },
    btnCancel() {
      this.formData = {
        id: this.equipmentId,
        nodeId: this.equipmentNodeId
      }
      this.$refs.editOrder.resetFields()
      this.$emit('update:showEditDialog', false)
    }
  }

}
</script>

<style>

</style>
